package com.leetcode.题库;

/**
 * @author 覃国强
 * @date 2022-02-25 17:13
 */
public class 题库_0007_整数反转 {

  public static void main(String[] args) {
    Solution solution = new Solution();
    int x = 123;
    solution.reverse(x);
  }

  static
  class Solution {

    public int reverse(int x) {
      int answer = 0;
      while (x != 0) {
        if (answer < Integer.MIN_VALUE / 10 || answer > Integer.MAX_VALUE / 10) {
          return 0;
        }
        int remainder = x % 10;
        x /= 10;
        answer = answer * 10 + remainder;
      }
      return answer;
    }
  }
}
